package org.gestorTareas.actions;

import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.gestorTareas.model.dao.UsuarioDao;
import org.gestorTareas.model.dto.Tarea;
import org.gestorTareas.model.dto.Usuario;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class TareaAction extends ActionSupport implements ModelDriven<Tarea> {

	private List<Tarea> tareas;

	private Tarea tarea = new Tarea();

	public String findTareasAll() throws Exception {

		WebApplicationContext context = WebApplicationContextUtils
				.getRequiredWebApplicationContext(ServletActionContext
						.getServletContext());

		UsuarioDao servicio = (UsuarioDao) context.getBean("UsuarioDao");
		this.tareas = servicio.list(Usuario.class);

		return SUCCESS;
	}

	public Tarea getModel(){
		return tarea;
	}
}
